#include "header.h"

int main(int argc, char** argv)
{
  work	  wrk;
  params  ctrl;
  int 	  nref, n2, N;

  init_restore(&argc, argv, &ctrl, &wrk);
  
  nref = (ctrl.n)/(ctrl.cmpn);
  n2 = (ctrl.cmpn)/2 + 1; N = ctrl.cmpn;

  FILE *fh_out = fopen("difference.dat", "w");
  fprintf(fh_out, "#1.u 2. D x-tilde 3. D y \n\n");
  fprintf(fh_out, "%.32Qe\t%.32Qe\t%.32Qe\n", 0.Q, 0.Q, cabsq(wrk.YY[0] - wrk.cmpYY[0]) );
  for (int j = 1; j < n2-1; j++) {
    fprintf(fh_out, "%.32Qe\t%.32Qe\t%.32Qe\n", 2.Q*pi*j/N, cabsq(wrk.XX[nref*j-1] - wrk.cmpXX[j-1]) , cabsq(wrk.YY[nref*j] - wrk.cmpYY[j]) );
  } 
  fprintf(fh_out, "%.32Qe\t%.32Qe\t%.32Qe\n", pi, 0.Q, cabsq(wrk.YY[nref*(n2-1)] - wrk.cmpYY[n2-1]));
  // must write other half
  for (int j = 1; j < n2-1; j++) {
    fprintf(fh_out, "%.32Qe\t%.32Qe\t%.32Qe\n", 2.Q*pi*(j+n2-1)/N, cabsq(wrk.XX[nref*(n2-j-1) - 1] - wrk.cmpXX[(n2-j-1)-1]),  cabsq(wrk.YY[nref*(n2-1-j)] - wrk.cmpYY[n2-1-j]) );
  }
  fclose(fh_out);


}
